package com.zzzyh.bookbackgroundsystem.service;

import com.zzzyh.bookbackgroundsystem.mapper.BookMapper;
import com.zzzyh.bookbackgroundsystem.pojo.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class BooksService {

    @Autowired
    public BookMapper bookMapper;
    public List<Book> getBooks(){
        return bookMapper.getAllBooks();
    }

    public Integer getBooksCount(){
        return bookMapper.getBookCount();
    }

    public List<Book> getBooksByPage(Integer offset, Integer count) {
        log.info("offset:{},count:{}", offset, count);
        return bookMapper.getBooksByPage(offset, count);
    }

    public boolean addBook(Book book) {
        return bookMapper.addBook(book)>=1;
    }

    public Book findBookById(Integer id) {
        return bookMapper.findBookById(id);
    }

    public boolean updateBook(Book book) {
        return bookMapper.updateBook(book)>=1;
    }

    public boolean deleteBook(Integer id) {
        return bookMapper.deleteBook(id)>=1;
    }
}
